package com.haixin.test.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.haixin.test.entity.User;
import com.haixin.test.serviceImpl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 请修改注释
 *
 * @author zhangjianshe
 * @date 2021.07.18
 */
@RestController
public class MybatisController {
    @Autowired
    private UserServiceImpl userService;

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable long id) {
        User user = userService.getUserById(id);
        return user;
    }
    @GetMapping("/userList")
    public PageInfo<User> listUser(
            @RequestParam(value = "page",required = false,defaultValue = "1") int page,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5") int pageSize
    ){
        List<User> result = userService.listUser(page,pageSize);
        PageInfo<User> pageInfo = new PageInfo<>(result);
        return pageInfo;
    }
}
